/**
 * 
 */
package mx.netbrain.bean;

import java.util.ArrayList;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import mx.netbrain.controller.OrganizationController;
import mx.netbrain.dao.OrganizationDao;
import mx.netbrain.dao.impl.OrganizationDaoImpl;
import mx.netbrain.model.Organization;

/**
 * @author julian
 * 
 */
public class OrganizationBean {

	private String name;
	private String descripcion;
	private Organization organization = new Organization();
	private List<Organization> listOrganization = new ArrayList<Organization>();

	public OrganizationBean() {
	}

	public void prepareOrganizacion(Long id) {
		organization = new Organization();
		OrganizationDao organizationDao = new OrganizationDaoImpl();
		organization = organizationDao.findById(id);
	}

	public void save() {
		OrganizationController
				.saveOrganization(organization, name, descripcion);
		FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO,
				"Datos guardado correctamente.", "");
		FacesContext.getCurrentInstance().addMessage(null, message);
		name = new String();
		descripcion = new String();
	}

	public void edit() {
		OrganizationController.updateOrganization(organization);
		FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_WARN,
				"Se actuaizaron los datos correctamente.", "");
		FacesContext.getCurrentInstance().addMessage(null, message);
	}

	public void delete() {
		OrganizationController.deleteOrganization(organization);
		FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
				"Se elimiaron los datos correctamente.", "");
		FacesContext.getCurrentInstance().addMessage(null, message);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescripcion() {
		return descripcion;
	}

	public void setDescripcion(String descripcion) {
		this.descripcion = descripcion;
	}

	public Organization getOrganization() {
		if (organization == null) {
			organization = new Organization();
		}
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	public List<Organization> getListOrganization() {
		OrganizationDao organizationDao = new OrganizationDaoImpl();
		listOrganization = organizationDao.listAll();
		return listOrganization;
	}

	public void setListOrganization(List<Organization> listOrganization) {
		this.listOrganization = listOrganization;
	}

}
